package jw3.c2.controller;
import jw3.c2.model.Administrator;
import jw3.c2.utils.DBConnection;
import jw3.c2.utils.QueryByClass;

import java.util.List;

import jw3.c2.model.Administrator;
import jw3.c2.model.Rooms_type;
import jw3.c2.model.Vip;
import jw3.c2.utils.DBConnection;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;

public class AdministratorController {
<<<<<<< HEAD
    public static boolean login(String Adm_Account, String Adm_Password) {
        try {
            QueryByClass<Administrator> qc = new QueryByClass<Administrator>();
            String sql = "select * from administrator where Adm_Account=? and Adm_Password=?";
            List<Administrator> list = qc.select(Administrator.class, sql, Adm_Account, Adm_Password);
            return list.size() > 0;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    public static boolean login1(String Adm_Account, String Adm_Phone) {
        try {
            QueryByClass<Administrator> qc = new QueryByClass<Administrator>();
            String sql = "select * from administrator where Adm_Account=? and Adm_Phone=?";
            List<Administrator> list = qc.select(Administrator.class, sql, Adm_Account, Adm_Phone);
            return list.size() > 0;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    public static boolean login2(String Adm_Password,String Adm_Account, String Adm_Phone) {
        try {
            String sql="UPDATE administrator SET Adm_Password=? WHERE Adm_Account=?  AND Adm_Phone=?";
            DBConnection.zsg(sql,Adm_Password,Adm_Account,Adm_Phone);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
=======




    //全查
    public static Vector<Vector<Object>> getAll() {
        String sql = "SELECT * FROM administrator;";
        //1、构造Vector类型用于赋值给表格
        Vector<Vector<Object>> data4 = new Vector<Vector<Object>>();
        try {
            Connection conn = DBConnection.getConnection();
            PreparedStatement ps = conn.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                // //创造对象，每次放一条数据
                Vector<Object> a = new Vector<Object>();

                //将每个字段放入对象
                a.add(rs.getInt("Adm_ID"));
                a.add(rs.getString("Adm_Account"));
                a.add(rs.getString("Adm_Password"));
                a.add(rs.getString("Adm_Phone"));
                //每次将一条数据加入到集合
                data4.add(a);
            }
            DBConnection.close(rs, ps, conn);
            return data4;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
>>>>>>> 41a53c21de81f762a7a7e8110a6b6a114ea5d254
    }

    //添加
    public static boolean register(Administrator administrator) {
        String sql="INSERT administrator VALUES(0,?,?,?)";
        return DBConnection.zsg(sql,administrator.getAdm_Accoount(),administrator.getAdm_Password(),administrator.getAdm_Phone());

    }
}
